﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using ClassLibrary.DAO;
using ClassLibrary.Utilities;
using System.Collections.Generic;
using ClassLibrary.Entity;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UpdateShoppingCartSession();
    }
    public void UpdateShoppingCartSession()
    {
        if (HttpContext.Current.Session[Global.SESSION_CART] != null)
        {
            List<TblOrderDetail> cartItems = (List<TblOrderDetail>)HttpContext.Current.Session[Global.SESSION_CART];

            int iQuantity = 0;
            double dAmount = 0;
            foreach (TblOrderDetail order in cartItems)
            {
                iQuantity += order.Quantity;
                //dAmount +=  order.TotalAmount;
                dAmount += order.Quantity * order.Price;
            }

            if (iQuantity == 0)
            {
                divShoppingCart.Attributes.Clear();
                divShoppingCart.Attributes.Add("class", "shoppingCartEmpty");
            }
            if (iQuantity == 1)
            {
                divShoppingCart.Attributes.Clear();
                divShoppingCart.Attributes.Add("class", "shoppingCartOne");
            }
            if (iQuantity == 2)
            {
                divShoppingCart.Attributes.Clear();
                divShoppingCart.Attributes.Add("class", "shoppingCartTwo");
            }
            if (iQuantity > 2)
            {
                divShoppingCart.Attributes.Clear();
                divShoppingCart.Attributes.Add("class", "shoppingCartThree");
            }

            lblItem.Text = iQuantity.ToString();
            lblAmout.Text = dAmount.ToString("0,00.##");
        }
    }

   
    protected void btsearch_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Products.aspx?text=" + HttpUtility.UrlEncode(txtSearch.Text.Trim()));
    }
}
